<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb5">
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        label-width="68px"
        class="el-form-search"
      >
        <el-form-item  prop="title" >
          <el-input
            v-model="queryParams.q"
            placeholder="标题、正文、关键字"
            clearable
            size="mini"
            @keyup.enter.native="handleQuery"
          />
        </el-form-item>
        <el-form-item class="el-form-search-item">
          <el-button
            type="primary"
            icon="el-icon-search"
            size="mini"
            @click="handleQuery"
          >搜索</el-button
          >
          <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
          >
        </el-form-item>
      </el-form>
    </el-row>

    <el-table
      :height="tableHeight"
      v-loading="loading"
      :data="dataList"
      @selection-change="handleSelectionChange"
      ref="dataTable"
    >
      <el-table-column label="#" type="index" width="50" align="center">
        <template scope="scope">
          <span>{{
              (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1
            }}</span>
        </template>
      </el-table-column>

      <el-table-column label="标题" align="center" prop="title"  width="480">
        <template scope="scope">
          <p v-html="scope.row.title"></p>
        </template>
      </el-table-column>
      <el-table-column label="正文" align="center" prop="content" width="520">
        <template scope="scope">
          <p v-html="scope.row.content"></p>
        </template>
      </el-table-column>
      <el-table-column label="主题" align="center" prop="topics"/>
      <el-table-column label="关键字" align="center" prop="keywords" width="180">
        <template scope="scope">
          <p v-html="scope.row.keywords"></p>
        </template>
      </el-table-column>
      <el-table-column label="来源" align="center" prop="source"  />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" />
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
      />
    </el-table>
  </div>
</template>

<script>
import {search} from "@/api/kb/searcher";
export default {
  name: "searcher",
  components: {},
  data() {
    return {
      // 表格高度
      tableHeight: document.documentElement.clientHeight - 180,
      // 遮罩层
      loading: true,
      // 选中id数组
      ids: [],
      //评价列表查询的id
      checkid: null,
      // 选中行数组
      selection: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示更多搜索条件
      showSearch: false,
      // 总条数
      total: 0,
      // 数据详情表格数据
      dataList: [],
      // 数据小区表格数据
      houseVillageList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 日期范围
      dateRange: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 20,
        orderByColumn: "create_time",
        isAsc: "desc",
        endTime: null,
        beginTime: null,
        q: null
      },
      // 数据亮点
      featureList: [],
      // 数据照片
      imageList: [],
      // 表单参数
      form: {},


    };
  },
  created() {
    this.getList();
  },
  methods: {
    handleClose(done) {
      this.$confirm("确认关闭？")
        .then((_) => {
          done();
        })
        .catch((_) => {});
    },

    /** 查询数据详情列表 */
    getList() {
      this.loading = true;
      search(this.queryParams).then((response) => {
        this.dataList = response.data.page.records;
        this.total = response.data.page.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {

      this.featureList = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.q=null;
      this.resetForm("queryForm");
      this.resetForm("queryMoreForm");
      this.handleQuery();
    },
    /** 更多搜索按钮 */
    handleMoreQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.selection = selection;
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
  },

  // 重新绘制表格，防止抖动与滚动条异常
  setDataTable() {
    this.$nextTick(() => {
      this.$refs.dataTable.doLayout();
    });
  },
};
</script>
